from flask import Blueprint, jsonify, request

from comm import get_data
from db import db1

bp_work = Blueprint("work", __name__)


@bp_work.route('/demp', methods=['POST', 'GET'])
def demp():
    if request.method == 'POST':
        data = get_data()
        sql = "insert into demp values (0,'%s',%d)" % (data['name'], int(data['count']))
        db1.insert(sql)
        return 'ok'
    else:
        sql = "select * from demp"
        res = db1.findall(sql)
        return jsonify({'code': 200, 'list': res})


@bp_work.route('/staff', methods=['POST', 'GET'])
def staff():
    if request.method == 'POST':
        data = get_data()
        sql = "insert into staff values (0,'%s','%s',%d,%d)" % (
            data['name'], data['sex'], int(data['money']), int(data['cid']))
        db1.insert(sql)
        return jsonify({'code': 200})
    else:
        pass
